module fft_wrap
USE FFTCF_INT

!----------------------------------------------
! VARIABLES
!----------------------------------------------

  use dimensions, only : jx, jz, jv

  real xWSAVE(4*jx+15), xCPY(2*jx)
  real zWSAVE(4*jz+15), zCPY(2*jz)
  real vWSAVE(4*jv+15), vCPY(2*jv)

!----------------------------------------------
! SUBROUTINES
!----------------------------------------------


contains

!-- fft initialization --

subroutine fft_init()

  implicit none

  call fftci(jx,xWSAVE)
  call fftci(jz,zWSAVE)
  call fftci(jv,vWSAVE)

end subroutine


!-- forward transform --

subroutine fft_forward(n, datain, dataout)

  implicit none

  integer  n
  complex  datain(:)
  complex  dataout(:)

  if (n .eq. jx) then

     call f2tcf(n, datain, dataout, xWSAVE, xCPY)

  else if (n .eq. jz) then

     call f2tcf(n, datain, dataout, zWSAVE, zCPY)

  else if (n .eq. jv) then

     call f2tcf(n, datain, dataout, vWSAVE, vCPY)

  else

     write (*,*) "wrond size of data"

  end if

end subroutine



!-- backward transform --


subroutine fft_backward(n, datain, dataout)

  implicit none

  integer  n
  complex  datain(:)
  complex  dataout(:)

  if (n .eq. jx) then

     call f2tcb(n, datain, dataout, xWSAVE, xCPY)

  else if (n .eq. jz) then

     call f2tcb(n, datain, dataout, zWSAVE, zCPY)

  else if (n .eq. jv) then

     call f2tcb(n, datain, dataout, vWSAVE, vCPY)

  else

     write (*,*) "wrond size of data"

  end if

end subroutine



end module
